package com.flipdf2.serialize.ppml;

import java.util.ArrayList;
import java.util.List;

public class AttributeType {

	public static class PPMLBoolean {
		public static final String YES = "Yes";
		public static final String NO = "No";

		public static String getString(boolean b) {
			return b ? YES : NO;
		}

		public static boolean getBoolean(String s) {
			return s.equals(YES);
		}
	}

	public static class PPMLIndexRange {
		// index range format: 1-9,11-20
		public static String getString(List<Integer[]> indexRangeList) {
			StringBuffer sBuf = new StringBuffer();
			for (int i = 0, n = indexRangeList.size(); i < n; i++) {
				Integer[] range = indexRangeList.get(i);
				sBuf.append(range[0] + "-" + range[1]);
				if (i != n - 1)
					sBuf.append(",");
			}
			return sBuf.toString();
		}

		public static List<Integer[]> getIndexRange(String value) {
			List<Integer[]> indexRangeList = new ArrayList<Integer[]>();
			String[] ranges = value.split(",");
			for (int i = 0, n = ranges.length; i < n; i++) {
				String[] range = ranges[i].split("-");
				if (range != null && range.length == 2) {
					Integer[] ii = new Integer[2];
					ii[0] = Integer.parseInt(range[0].trim());
					ii[1] = Integer.parseInt(range[0].trim());
					indexRangeList.add(ii);
				}
			}
			return indexRangeList;
		}
	}
	
	public static class PPMLWeight {
		public static final int MIN = 1;
		public static final int MAX = 100;
		
		public static boolean isValid(int weight) {
			return (weight >= MIN && weight <= MAX);
		}
	}
}
